﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PrinteMaster
{
    public partial class 确认客户端自助充值 : Form
    {
        public 确认客户端自助充值()
        {
            InitializeComponent();
        }

        private void timer1sec_Tick(object sender, EventArgs e)
        {

        }

        private void dgv_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (MessageBox.Show("是否确认选定的充值请求?", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        //发起标准充值
                        DataBase.Error er = DataBase.getInstance().addUserMoney(
                            this.req.Tables[0].Rows[dgv.CurrentRow.Index][1].ToString(),
                            Convert.ToDouble(this.req.Tables[0].Rows[dgv.CurrentRow.Index][2].ToString()));
                        if (er != DataBase.Error.ok)
                        {
                            MessageBox.Show("数据库错误,发起充值失败！=>" + er);
                            return;
                        }

                        var str = this.req.Tables[0].Rows[dgv.CurrentRow.Index][0].ToString();
                        MySqlHelper.GetDataSet(MySqlHelper.Conn, CommandType.Text, "update 充值消息推送 set 确认情况='已确认' where 编号 = " + str);

                        MessageBox.Show("确认成功!");
                        

                        //更新界面
                        str = string.Format("select * from 充值消息推送 where 确认情况='未确认'");
                        req = MySqlHelper.GetDataSet(MySqlHelper.Conn, CommandType.Text, str, null);

                        dgv.DataSource = req.Tables[0].DefaultView;
                        //隐藏无关信息
                        dgv.Columns[0].Visible = false;

                    }
                    catch (Exception ex) { Console.Write(ex.Message); MessageBox.Show("数据库错误，错误原因=>" + ex.Message); }

                }
            }
        }
        private DataSet req = null;
        private void 确认客户端自助充值_Load(object sender, EventArgs e)
        {
            //更新界面
            var str = string.Format("select * from 充值消息推送 where 确认情况='未确认'");
            req = MySqlHelper.GetDataSet(MySqlHelper.Conn, CommandType.Text, str, null);

            dgv.DataSource = req.Tables[0].DefaultView;
            //隐藏无关信息
            dgv.Columns[0].Visible = false;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //更新界面
            var str = string.Format("select * from 充值消息推送 where 确认情况='未确认'");
            req = MySqlHelper.GetDataSet(MySqlHelper.Conn, CommandType.Text, str, null);
            if (req.Tables[0].Rows.Count != 0)

                dgv.DataSource = req.Tables[0].DefaultView;
            //隐藏无关信息
            dgv.Columns[0].Visible = false;

        }
    }
}
